package com.dh.service.Impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.dh.mapper.UserMapper;
import com.dh.pojo.User;
import com.dh.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * 用户Service实现类
 */
@Service
public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements UserService {

    @Autowired
    private UserMapper userMapper;
    /**
     * 根据用户名查询用户对象
     * @param user
     */

    @Override
    public User queryUserByUsername(User user) {
        //条件构造器 动态拼接where条件 原则: 根据对象中不为null的属性动态拼接where条件.
        QueryWrapper<User> wrapper = new QueryWrapper<>();
        //根据username去查询
        wrapper.eq("username", user.getUsername());
        //返回 查询的一条记录
        return userMapper.selectOne(wrapper);
    }
}
